public class FoxSequence {
	public String isValid(int[] seq) {
		int seqLength = seq.length;
		for (int a = 1; a < seqLength; a++) {
			if (!isPositiveArithmetic(seq, 0, a))
				continue;
			for (int b = a + 1; b < seqLength; b++) {
				if (!isNegativeArithmetic(seq, a, b))
					continue;
				for (int c = b; c < seqLength; c++) {
					if (!equal(seq, b, c))
						continue;
					for (int d = c + 1; d < seqLength - 1; d++) {
						if (!isPositiveArithmetic(seq, c, d))
							continue;
						if (!isNegativeArithmetic(seq, d, seqLength - 1))
							continue;
						return "YES";
					}
				}
			}
		}
		return "NO";
	}

	private boolean equal(int[] seq, int from, int to) {
		return getType(seq, from, to) == 3;
	}

	private boolean isNegativeArithmetic(int[] seq, int from, int to) {
		return getType(seq, from, to) == 2;
	}

	private boolean isPositiveArithmetic(int[] seq, int from, int to) {
		return getType(seq, from, to) == 1;
	}

	private int getType(int[] seq, int from, int to) {
		if (from == to)
			return 3;
		int difference = seq[from + 1] - seq[from];
		for (int i = from + 2; i <= to; i++) {
			if (seq[i] - seq[i - 1] != difference)
				return 0;
		}
		if (difference > 0)
			return 1;
		if (difference < 0)
			return 2;
		return 3;
	}


	// BEGIN CUT HERE
	public static void main(String[] args) {
		if (args.length == 0) {
			FoxSequenceHarness.run_test(-1);
		} else {
			for (int i=0; i<args.length; ++i)
				FoxSequenceHarness.run_test(Integer.valueOf(args[i]));
		}
	}
// END CUT HERE
}

// BEGIN CUT HERE
class FoxSequenceHarness {
	public static void run_test(int casenum) {
		if (casenum != -1) {
			if (runTestCase(casenum) == -1)
				System.err.println("Illegal input! Test case " + casenum + " does not exist.");
			return;
		}
		
		int correct = 0, total = 0;
		for (int i=0;; ++i) {
			int x = runTestCase(i);
			if (x == -1) {
				if (i >= 100) break;
				continue;
			}
			correct += x;
			++total;
		}
		
		if (total == 0) {
			System.err.println("No test cases run.");
		} else if (correct < total) {
			System.err.println("Some cases FAILED (passed " + correct + " of " + total + ").");
		} else {
			System.err.println("All " + total + " tests passed!");
		}
	}
	
	static boolean compareOutput(String expected, String result) { return expected.equals(result); }
	static String formatResult(String res) {
		return String.format("\"%s\"", res);
	}
	
	static int verifyCase(int casenum, String expected, String received) { 
		System.err.print("Example " + casenum + "... ");
		if (compareOutput(expected, received)) {
			System.err.println("PASSED");
			return 1;
		} else {
			System.err.println("FAILED");
			System.err.println("    Expected: " + formatResult(expected)); 
			System.err.println("    Received: " + formatResult(received)); 
			return 0;
		}
	}

	static int runTestCase(int casenum) {
		switch(casenum) {
		case 0: {
			int[] seq                 = {1,3,5,7,5,3,1,1,1,3,5,7,5,3,1} ;
			String expected__         = "YES";

			return verifyCase(casenum, expected__, new FoxSequence().isValid(seq));
		}
		case 1: {
			int[] seq                 = {1,2,3,4,5,4,3,2,2,2,3,4,5,6,4} ;
			String expected__         = "YES";

			return verifyCase(casenum, expected__, new FoxSequence().isValid(seq));
		}
		case 2: {
			int[] seq                 = {3,6,9,1,9,5,1} ;
			String expected__         = "YES";

			return verifyCase(casenum, expected__, new FoxSequence().isValid(seq));
		}
		case 3: {
			int[] seq                 = {1,2,3,2,1,2,3,2,1,2,3,2,1} ;
			String expected__         = "NO";

			return verifyCase(casenum, expected__, new FoxSequence().isValid(seq));
		}
		case 4: {
			int[] seq                 = {1,3,4,3,1,1,1,1,3,4,3,1} ;
			String expected__         = "NO";

			return verifyCase(casenum, expected__, new FoxSequence().isValid(seq));
		}
		case 5: {
			int[] seq                 = {6,1,6} ;
			String expected__         = "NO";

			return verifyCase(casenum, expected__, new FoxSequence().isValid(seq));
		}

		// custom cases

/*      case 6: {
			int[] seq                 = ;
			String expected__         = ;

			return verifyCase(casenum, expected__, new FoxSequence().isValid(seq));
		}*/
/*      case 7: {
			int[] seq                 = ;
			String expected__         = ;

			return verifyCase(casenum, expected__, new FoxSequence().isValid(seq));
		}*/
/*      case 8: {
			int[] seq                 = ;
			String expected__         = ;

			return verifyCase(casenum, expected__, new FoxSequence().isValid(seq));
		}*/
		default:
			return -1;
		}
	}
}

// END CUT HERE
